Skip to content

feat: Change type of PromptModel invocation_layer_class init param#6497

Merged
silvanocerza merged 1 commit into
v1.xfrom
prompt-model-invocation-layer
Dec 6, 2023
Merged

feat: Change type of PromptModel invocation_layer_class init param#6497
silvanocerza merged 1 commit into
v1.xfrom
prompt-model-invocation-layer

Conversation

@silvanocerza
Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

This PR changes PromptModel invocation_layer_class init parameter type. Now it can either be a PromptModelInvocationLayer class or str pointing to the invocation layer class.

If str is used the class module will be imported automatically.

Example usage:

model = PromptModel(
    invocation_layer_class="haystack.nodes.prompt.invocation_layer.CohereInvocationLayer", api_key="fake_api_key"
)

How did you test it?

I added a unit test and tested serialisation manually.

Notes for the reviewer

This is not a complete fix to the serialisation issue but at least it makes possible to set a custom invocation_layer_class in YAML.

Checklist

@silvanocerza silvanocerza self-assigned this Dec 6, 2023
@silvanocerza silvanocerza requested review from a team as code owners December 6, 2023 13:45
@silvanocerza silvanocerza requested review from anakin87 and dfokina and removed request for a team December 6, 2023 13:45
@silvanocerza silvanocerza changed the base branch from main to v1.x December 6, 2023 13:46
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Dec 6, 2023
Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice fix! 🙏

@silvanocerza silvanocerza merged commit 6e20adf into v1.x Dec 6, 2023
@silvanocerza silvanocerza deleted the prompt-model-invocation-layer branch December 6, 2023 17:17
anakin87 pushed a commit that referenced this pull request Dec 21, 2023
…eciprocal rank fusion (#5704)

* Change type of PromptModel invocation_layer_class init param (#6497)

* fix: mypy `"str" not callable` for `PromptModelInvocationLayer` (#6529)

* cast to PromptModelInvocationLayer

* fix pylint pointless-exception-statement

* use two variables to avoid re-assignment

* black

* use mocked tokenizer in unit test

* Add normalization and weighting for `JoinDocuments` reciprocal rank fusion

* Add weights and score normalization for reciprocal rank fusion in JoinDocuments node.

* Fix black-jupyter

* Fix JoinDocuments test for rrf + score normalization

---------

Co-authored-by: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com>
Co-authored-by: Julian Risch <julian.risch@deepset.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Serialisation of the PromptModel is broken if the invocation_layer_class param is set, both from and to yaml

2 participants